<?php
  if (isset($_REQUEST['onsub'])){
    if( $_REQUEST['onsub']=='ok') {
	    require_once dirname(__FILE__) . '/../DbUtils.class.php';
			require_once dirname(__FILE__) . '/../includes/smarty.inc.php';
			require_once dirname(__FILE__) . '/../includes/MiscUtils.class.php';
			require_once dirname(__FILE__) . '/../server.class.php';
			require_once dirname(__FILE__) . '/../metadata.php';
			$myPdo = DbUtils::createPdoInst();
			
			
			$cond_vals = NULL;
            $opt = new stdClass();
            $opt->select_expr = 'DISTINCT t.id, t.status,  t.g_name, t.g_phone, t.g_mobile, t.b_name, t.b_phone, t.b_mobile';
			$enquiries = DbUtils::get($myPdo, TABLE_NAME_PREFIX_MODULE . 'data_enquiry', $cond_vals, 't.id', 'ASC', NULL, NULL, $opt)->d;
			
			$export_name = BRANCH . ' -- All Enquiries';
	        header("Content-Type: application/vnd.ms-excel;");
	        header("Content-Disposition: attachment;filename=$export_name.xls");
    
      echo"<table border='1'><tr>";
      echo " <td colspan='8' height='30px' align='center'><h3>".$export_name."</h3></td></tr><tr height='27' style='font-weight:bold;'>";
      echo   "<td>Enquiry #</td>";
      echo   "<td>Groom Name</td>";
      echo   "<td>Groom Phone</td>";
      echo   "<td>Groom Mobile</td>";
      echo   "<td>Bride Name</td>";
      echo   "<td>Bride Phone</td>";
      echo   "<td>Bride Mobile</td>";
      echo   "<td>Status</td>";
      echo  "</tr>";  
      
      if (count($enquiries) == 0) {
        echo "<tr><td colspan='8'>No Results Found</td></tr>";
      }
    
      foreach ($enquiries as &$enq) {
        echo" <tr>";
        echo   "<td>" . Server::customerId($enq->id) ."</td>";
        echo   "<td>" .  $enq->g_name. "</td>";
        echo   "<td>" .  $enq->g_phone. "</td>";
        echo   "<td>" .  $enq->g_mobile. "</td>";
        echo   "<td>" .  $enq->b_name. "</td>";
        echo   "<td>" .  $enq->b_phone. "</td>";
        echo   "<td>" .  $enq->b_mobile. "</td>";
        if ($enq->status == 0) {
          $status = 'Enquiried';
        } else if ($enq->status == 1) {
           $status = 'Booked';
        } else if ($enq->status == 2) {
          $status = 'Failed';
        }
        echo   "<td>" .  $status. "</td>";
        echo  "</tr>";
      }
      echo"</table>";
      die;
    }
  }

?>

<br>
<div>
  <fieldset>
    <legend>Enquiry</legend>
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
      <label><span style="color:red;font-weight:bolder;">Date format: 2013-03-01</span></label><br>
      <label>C/Date<input type="text" name ="begin_date" id="begin_date"></label><label> TO <input type="text" name ="end_date" id="end_date"></label>
      <label><input type="hidden" name="onsub" id="onsub"  value="ok">
      <input type="submit" value="download"></label>
    </form>
  </fieldset>
</div>
 